package
{
	public class Partida
	{
		
		public static const INDEX_ARRAY:Array = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
		private var _randomizedArray:Array = new Array();
		private var _numErros:Number;
		private var _numAcertos:Number;
		private var _score:Number;
		
		public function Partida()
		{
			// inicia o array de índices aleatórios dos pares de imagens
			_randomizedArray = randomizeArray(INDEX_ARRAY);
			
			// inicia os parâmetros iniciais da partida
			numErros = 0;
			_numAcertos = 0;
			
		}
		
		public function get randomizedArray():Array
		{
			return _randomizedArray;
		}
		
		private function set randomizedArray(value:Array):void
		{
			_randomizedArray = value;
		}
		
		private function get numErros():Number
		{
			return _numErros;
		}
		
		private function set numErros(value:Number):void
		{
			_numErros = value;
		}
		
		public function get numAcertos():Number
		{
			return _numAcertos;
		}
		
		private function set numAcertos(value:Number):void
		{
			_numAcertos = value;
		}
		
		public function get score():Number
		{
			if(numErros != 0 || _numAcertos != 0){
				_score = Math.round((_numAcertos / (numErros + _numAcertos)) * 100);
				return _score;
			} else {
				return 0;
			}
			
		}
		
		private function randomizeArray(array:Array):Array
		{
				
				for (var i:int = 0; i < array.length; i++) 
				{
					for (var j:int = 0; j < array.length - 1; j++) 
					{
						var temp:int;
						
						var randNumber1:Number;
						randNumber1 = Math.random();
						
						var randNumber2:Number;
						randNumber2 = Math.random();
						
						if (randNumber2 > randNumber1) 
						{
							temp = array[j + 1];
							array[j + 1] = array[j];
							array[j] = temp;
						}						
						
					}
					
				}
				return array;
			
		}

		public function missPt():void
		{
			numErros += 1;
		}
		
		public function winPt():void
		{
			_numAcertos += 1;
		}
		
	}
}